home *** CD-ROM | disk | FTP | other *** search
/ Eagles Nest BBS 8 / Eagles_Nest_Mac_Collection_Disc_8.TOAST / Developer Tools⁄Additions / MacsbugBook / MacsBug Book Disk / Debugger Prefs sources / put.c / put.c
Encoding:
C/C++ Source or Header  |  1990-03-30  |  3.6 KB  |  206 lines  |  [TEXT/MPS ]

  1. /*    put.c
  2.     This is a set of formatting routines for use by dcmds.
  3.     Copyright © 1988-1990 Apple Computer, Inc.  All rights reserved.
  4.  
  5.     Modification history:
  6.         29Mar90    sad        use dcmdScroll and dcmdDrawText
  7.         10Oct89    sad        add PutUHexLong; change PutPStr types to unsigned char*
  8.         12Aug89    sad     added PutDec and PutDec1
  9.         29Nov88 sad        revised for new dcmd names.
  10.          5Oct88 sad        written from file.c
  11.  */
  12.  
  13. #include <Types.h>
  14. #include <Memory.h>
  15.  
  16. #include "dcmd.h"
  17.  
  18. static Str255 line;
  19. static int linepos = 0;
  20.  
  21.  
  22. void PutLine()
  23. {
  24.     dcmdScroll();
  25.     dcmdDrawText((Ptr)line, linepos);
  26.     linepos = 0;
  27. } // PutLine
  28.  
  29.  
  30. void PutChar(char c)
  31. {
  32.     line[linepos++] = c;
  33. } // PutChar
  34.  
  35.  
  36. void PutSpace()
  37. {
  38.     PutChar(' ');
  39. } // PutSpace
  40.  
  41.  
  42. void PutSpacesTo(int pos)
  43. {
  44.     while (linepos < pos) PutSpace();
  45. } // PutSpacesTo
  46.  
  47.  
  48. void PutBytesTruncTo(const char* s, int len, int pos)
  49. {
  50.     if (pos > linepos)
  51.         {
  52.         if (len <= pos - linepos)
  53.             {
  54.             BlockMove(s,line+linepos,len);
  55.             linepos += len;
  56.             while (linepos < pos) PutSpace();
  57.             }
  58.         else
  59.             {
  60.             BlockMove(s,line+linepos,pos-linepos-1);
  61.             linepos = pos - 1;
  62.             PutChar('…');
  63.             }
  64.         line[linepos] = '\0';
  65.         }
  66. } // PutBytesTruncTo
  67.  
  68.  
  69. void PutBytesTo(const char* s, int len, int pos)
  70. {
  71.     BlockMove(s,line+linepos,len);
  72.     linepos += len;
  73.     while (linepos < pos) PutSpace();
  74.     line[linepos] = '\0';
  75. } // PutBytesTo
  76.  
  77.  
  78. void PutCStrTo(const char* s, int pos)
  79. {
  80.     int slen = strlen(s);
  81.     PutBytesTo(s,slen,pos);
  82. } // PutCStrTo
  83.  
  84.  
  85. void PutCStrTruncTo(const char* s, int pos)
  86. {
  87.     int slen = strlen(s);
  88.     PutBytesTruncTo(s,slen,pos);
  89. } // PutCStrTo
  90.  
  91.  
  92. void PutCStr(const char* s)
  93. {
  94.     int slen = strlen(s);
  95.     PutBytesTo(s,slen,0);
  96. } // PutCStr
  97.  
  98.  
  99. void PutPStrTruncTo(const unsigned char* s, int pos)
  100. {
  101.     int slen = *s;
  102.     PutBytesTruncTo((const char*)s+1,slen,pos);
  103. } // PutPStrTo
  104.  
  105.  
  106. void PutPStrTo(const unsigned char* s, int pos)
  107. {
  108.     int slen = *s;
  109.     PutBytesTo((const char*)s+1,slen,pos);
  110. } // PutPStrTo
  111.  
  112.  
  113. void PutPStr(const unsigned char* s)
  114. {
  115.     int slen = *s;
  116.     PutBytesTo((const char*)s+1,slen,0);
  117. } // PutPStr
  118.  
  119.  
  120. void PutUHexZTo(unsigned long i, int ndig, int pos)
  121. {
  122. unsigned long dig = i % 0x10;
  123. unsigned long rest = i / 0x10;
  124.     if (rest != 0) PutUHexZTo(rest,ndig - 1,pos - 1);
  125.     else
  126.         {
  127.         pos -= 1;        // one for this digit
  128.         if (ndig > 0) pos -= ndig - 1;        // the leading zeros
  129.         while (linepos < pos) PutSpace();
  130.         while (--ndig > 0) PutChar('0');
  131.         }
  132.     if (dig < 10) PutChar('0' + dig);
  133.     else PutChar('a' + (dig - 10));
  134. } // PutUHexZTo
  135.  
  136.  
  137. void PutUHexZ(unsigned long i, int nz)
  138. {
  139.     PutUHexZTo(i,nz,0);
  140. } // PutUHexZ
  141.  
  142.  
  143. void PutUHexWord(unsigned short i)
  144. {
  145.     PutUHexZTo(i,4,0);
  146. } // PutUHexWord
  147.  
  148.  
  149. void PutUHexLong(unsigned long i)
  150. {
  151.     PutUHexZTo(i,8,0);
  152. } // PutUHexLong
  153.  
  154.  
  155. void PutUDecTo(unsigned long i, int pos)
  156. {
  157. unsigned long dig = i % 10;
  158. unsigned long rest = i / 10;
  159.     if (rest != 0) PutUDecTo(rest,pos - 1);
  160.     else
  161.         {
  162.         pos -= 2;    // one for the '#' and one for this digit
  163.         while (linepos < pos) PutSpace();
  164.         PutChar('#');
  165.         }
  166.     PutChar('0' + dig);
  167. } // PutUDecTo
  168.  
  169.  
  170. void PutUDec(unsigned long i)
  171. {
  172.     PutUDecTo(i,0);
  173. } // PutUDec
  174.  
  175.  
  176. static void PutDec1(unsigned long i, int neg)
  177. {
  178. unsigned long dig = i % 10;
  179. unsigned long rest = i / 10;
  180.     if (rest != 0) PutDec1(rest, neg);
  181.     else
  182.         {
  183.         PutChar('#');
  184.         if (neg) PutChar('-');
  185.         }
  186.     PutChar('0' + dig);
  187. }
  188.  
  189. void PutDec(long i)
  190. {
  191.     // on a 2’s complement machine you can’t negate most negative long, but
  192.     //    it turns out that you get the right answer anyway
  193.     if (i < 0) PutDec1(-i,1);        // *** can’t negate most negative number!
  194.     else
  195.         PutDec1(i,0);
  196. } // PutDec
  197.  
  198.  
  199. void PutOSType(unsigned long typ)
  200. {
  201.     PutChar((typ>>24) & 0xff);
  202.     PutChar((typ>>16) & 0xff);
  203.     PutChar((typ>>8) & 0xff);
  204.     PutChar(typ & 0xff);
  205. } // PutOSType
  206.